#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#define EVENT_BLINK_TIME 500
#define CONNECTION_TIMEOUT 1000
#define ON_TEXT "<font color=green>ON</font>"
#define OFF_TEXT "<font color=red>OFF</font>"
#define EMPTY_TEXT "N/A"

#include <QApplication>
#include <QCloseEvent>

#include <QDialog>
#include <QMessageBox>
#include <QLabel>
#include <QPushButton>
#include <QProgressBar>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QGroupBox>

#include <QAction>
#include <QMenu>
#include <QDate>
#include <QTime>
#include <QTextStream>


#include "optionsdialog.h"
#include "connectionthread.h"
#include "ipchangethread.h"

#include <QTimer>
#include <QtNetwork/QHostAddress>
#include <QtNetwork/QTcpSocket>
#include <QSystemTrayIcon>

#include <phonon/MediaObject>
#include <phonon/AudioOutput>
#include <phonon/Path>


class MainWindow: public QDialog{
    Q_OBJECT
    const QString powerString;
    const int max_alarms;
    QHBoxLayout* mainLayout;
    QGridLayout* alarmLayout;
    QVBoxLayout* toolsLayout;
    QHBoxLayout* batteryLayout;
    QVBoxLayout* infoLayout;
    QGroupBox* alarmGroupBox;
    QGroupBox* infoGroupBox;
    QLabel** alarmNameLabels;
    QLabel** alarmStatusLabels;
    QLabel* connectionStatus;
    QLabel* powerLabel;
    QLabel* batteryLabel;
    QPushButton* optionsButton;
    QPushButton* connectButton;
    QTimer* eventTimer;
    QTimer* timeoutTimer;
    OptionsDialog* optionsDialog;
    ConnectionThread* cThread;
    IpChangeThread* ipcThread;
    QProgressBar* batteryProgressBar;
    QSystemTrayIcon* tray;

    Phonon::MediaObject* mediaObject;
    Phonon::AudioOutput* ado;

    QStringList audioFiles;
    QString errorAudioFile;
    QString hostIPString;
    bool* alarmsEnabled;
    bool* alarmEvents;
    bool noRespondEvent;
    bool connected;
    bool playSound;
    bool power;

    void initVars();
    void createLayout();
    void createSystemTray();
    void makeConnections();
    void initConnectionThread();
    void log(QString ev);

protected:
    void closeEvent(QCloseEvent *e);
public:
    MainWindow(QWidget* = 0);
    ~MainWindow();
signals:

private slots:
    void connectedToHost();
    void disconnectedFromHost();
    void connectionTimeout();
    void startStopConnection();
    void loadSettings();
    void showMainWindow(QSystemTrayIcon::ActivationReason r);
    void updateAlarm();
    void alarmEvent(int, bool);
    void connectionError();
    void setInfo(int b, bool p, bool s);
    void changeIp(QString i, QString m);
    void ipChangeMessage(QString msg);
};


#endif // MAINWINDOW_H
